﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WordWonderGame.UI
{
    public partial class ChonDapAnMan1UI : UserControl
    {
        public ChonDapAnMan1UI()
        {
            InitializeComponent();
        }
        public event EventHandler ChonDung;
        public event EventHandler ChonSai;

        string traLoi;
        bool traLoiRoi;
        Button btDung;
        public void LoadDapAn(List<string> dapAn)
        {
            traLoi = dapAn[0];
            traLoiRoi = false;
            Random r = new Random();
            int d1 = r.Next(0, 4);
            btDA1.Text = dapAn[d1];
            if (dapAn[d1] == traLoi)
            {
                btDung = btDA1;
            }
            btDA1.BackgroundImage = imageDAs.Images[0];
            dapAn.RemoveAt(d1);
            int d2 = r.Next(0, 3);
            btDA2.Text = dapAn[d2];
            if (dapAn[d2] == traLoi)
            {
                btDung = btDA2;
            }
            btDA2.BackgroundImage = imageDAs.Images[0];
            dapAn.RemoveAt(d2);

            int d3 = r.Next(0, 2);
            btDA3.Text = dapAn[d3];
            if (dapAn[d3] == traLoi)
            {
                btDung = btDA3;
            }
            btDA3.BackgroundImage = imageDAs.Images[0];
            dapAn.RemoveAt(d3);

            btDA4.Text = dapAn[0];
            if (dapAn[0] == traLoi)
            {
                btDung = btDA4;
            }
            btDA4.BackgroundImage = imageDAs.Images[0];
        }

        private void btDA1_Click(object sender, EventArgs e)
        {
            if (!traLoiRoi)  
            {
                if (btDA1.Text == traLoi)
                {
                    btDA1.BackgroundImage = imageDAs.Images[1];
                    if (ChonDung != null)
                    {
                        ChonDung(this, null);
                    }
                }
                else
                {
                    btDA1.BackgroundImage = imageDAs.Images[2];
                    if (ChonSai != null)
                    {
                        ChonSai(this, null);
                    }
                }
            }
            btDung.BackgroundImage = imageDAs.Images[1];
            traLoiRoi = true;
        }

        private void btDA2_Click(object sender, EventArgs e)
        {
            if (!traLoiRoi)
            {
                if (btDA2.Text == traLoi)
                {
                    btDA2.BackgroundImage = imageDAs.Images[1];
                    if (ChonDung != null)
                    {
                        ChonDung(this, null);
                    }
                }
                else
                {
                    btDA2.BackgroundImage = imageDAs.Images[2];
                    if (ChonSai != null)
                    {
                        ChonSai(this, null);
                    }
                }
            }
            btDung.BackgroundImage = imageDAs.Images[1];
            traLoiRoi = true;
        }

        private void btDA3_Click(object sender, EventArgs e)
        {
            if (!traLoiRoi)
            {
                if (btDA3.Text == traLoi)
                {
                    btDA3.BackgroundImage = imageDAs.Images[1];
                    if (ChonDung != null)
                    {
                        ChonDung(this, null);
                    }
                }
                else
                {
                    btDA3.BackgroundImage = imageDAs.Images[2];
                    if (ChonSai != null)
                    {
                        ChonSai(this, null);
                    }
                }
            }
            btDung.BackgroundImage = imageDAs.Images[1];
            traLoiRoi = true;
        }

        private void btDA4_Click(object sender, EventArgs e)
        {
            if (!traLoiRoi)
            {
                if (btDA4.Text == traLoi)
                {
                    btDA4.BackgroundImage = imageDAs.Images[1];
                    if (ChonDung != null)
                    {
                        ChonDung(this, null);
                    }
                }
                else
                {
                    btDA4.BackgroundImage = imageDAs.Images[2];
                    if (ChonSai != null)
                    {
                        ChonSai(this, null);
                    }
                }
            }
            btDung.BackgroundImage = imageDAs.Images[1];
            traLoiRoi = true;
        }





        public void HienDapAn()
        {
            btDung.BackgroundImage = imageDAs.Images[1];
        }
    }
}
